import pymysql

from aestate.base.anno import Table
from aestate.base.model import Model
from aestate.dbs import mysql
from aestate.dbs._mysql import tag
from aestate.work.Annotation import AopModel, SelectAbst, Select
from db_base import MyAdapter


def Before():
    print("before")


def After(result):
    print('result', result)


class BaseModel(Model):
    class Log:
        enable = True
        path = '/log/'

    class Config(Model.Config):
        dbtype = mysql
        creator = pymysql
        log_conf = {
            # 保存位置
            'path': "/log/",
            # 是否允许保存日志
            'save_flag': True,
            # 当日志到达多少MB时删除日志重新记录
            'max_clear': 10
        }
        print_sql = True
        last_id = True
        adapter = MyAdapter

    class Database:
        # 数据库地址
        host = '127.0.0.1',
        # 数据库端口
        port = 3306,
        # 数据库名
        database = 'demo',
        # 数据库用户
        user = 'root',
        # 数据库密码
        password = '123456',
        # 数据库创建者，如果你用的是mysql，那么这里就是pymysql，如果用的是sqlserver，那么这里就应该是pymssql
        db_type = 'pymysql'


@Table(name='demo', msg='示例表')
class DemoNotNew(BaseModel):
    name = tag.varcharField(length=20, is_null=False, comment='名称')
    password = tag.varcharField(length=20, is_null=False, comment='密码')

    class Operas(Model.Operas):
        @AopModel(before=Before, after=After)
        @Select("SELECT * FROM demo WHERE id = ${id} AND name = #{name}")
        def find_all_where_id(self, id, name): ...

        @SelectAbst()
        def find_all_F_where_id_eq_and_name_eq(self, **kwargs): ...

        @SelectAbst()
        def find_all_F_where_id_in_and_name_like_order_by_id(self, **kwargs) -> list: ...

        @AopModel(before=Before, after=After)
        @SelectAbst()
        def find_all_F(self, **kwargs): ...


print(DemoNotNew.__dict__)
